//
//  PublicCategoryElementModel.m
//  Btpin
//
//  Created by Vic on 2019/3/13.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PublicCategoryElementModel.h"

@implementation PublicCategoryElementModel

- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues {
    self.id = [UIToolsControl dataAnalysis:keyedValues[@"id"]];
    self.name = [UIToolsControl dataAnalysis:keyedValues[@"name"]];
    self.titleName = @"";
    self.idstr = [UIToolsControl dataAnalysis:keyedValues[@"idstr"]];
    
    self.spell = [UIToolsControl dataAnalysis:keyedValues[@"spell"]];
    self.pid = [UIToolsControl dataAnalysis:keyedValues[@"pid"]];
    
    self.detail = @"";
    self.selectType = SelectTypeOfMultiSelect;
    self.itemWidth = MAX([UIToolsControl textWidth:self.name size:CGSizeMake(MAXFLOAT, 30*Scale) font:Font_13]+13*Scale, ceil((WIDTH-60*Scale)/3)-1);
    self.isSelect = NO;
    self.addNewItem = NO;
    self.canTapFlag = NO;
    
    self.code = [UIToolsControl dataAnalysis:keyedValues[@"code"]];
    self.ecode = [UIToolsControl dataAnalysis:keyedValues[@"ecode"]];
    self.ename = [UIToolsControl dataAnalysis:keyedValues[@"ename"]];
    
    self.childArray = [NSMutableArray arrayWithCapacity:0];
    NSArray *childrens = keyedValues[@"child"];
    for (NSInteger i = 0; i < childrens.count; i++) {
        PublicCategoryElementModel *model = [[PublicCategoryElementModel alloc] init];
        [model setValuesForKeysWithDictionary:childrens[i]];
        [self.childArray addObject:model];
    }
    
    self.jobCatsArrayForTworThreeLevel = [NSMutableArray arrayWithCapacity:0];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (id)copyWithZone:(NSZone *)zone {
    PublicCategoryElementModel *model = [[[self class] allocWithZone:zone] init];
    model.id = self.id;
    model.name = self.name;
    model.titleName = self.titleName;
    model.idstr = self.idstr;
    
    model.spell = self.spell;
    model.pid = self.pid;
    
    model.detail = self.detail;
    model.selectType = self.selectType;
    model.itemWidth = self.itemWidth;
    model.isSelect = self.isSelect;
    model.addNewItem = self.addNewItem;
    model.canTapFlag = self.canTapFlag;
    
    model.code = self.code;
    model.ecode = self.ecode;
    model.ename = self.ename;
    
    model.childArray = [NSMutableArray arrayWithCapacity:0];
    if (self.childArray && self.childArray.count) {
        for (NSInteger i = 0; i < self.childArray.count; i++) {
            [model.childArray addObject:[self.childArray[i] copy]];
        }
    }
    model.jobCatsArrayForTworThreeLevel = [NSMutableArray arrayWithCapacity:0];
    if (self.jobCatsArrayForTworThreeLevel && self.jobCatsArrayForTworThreeLevel.count) {
        for (NSInteger i = 0; i < self.jobCatsArrayForTworThreeLevel.count; i++) {
            [model.jobCatsArrayForTworThreeLevel addObject:[self.jobCatsArrayForTworThreeLevel[i] copy]];
        }
    }
    
    return model;
}

@end
